package com.whzm.web;

import com.whzm.pojo.MemberOrder;
import com.whzm.pojo.MemberType;
import com.whzm.pojo.Resources;
import com.whzm.service.MemberInfoService;
import com.whzm.service.MemberResources;
import com.whzm.util.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/*
* 会员充值，支付回调，轮询
* */
@RequestMapping("/member-info")
@RestController
public class MemberInfoController {
    @Autowired
    MemberInfoService memberInfoService;
    @Autowired
    MemberResources memberResources;


    /**获取高管资源,获取品牌广告商(1流量，2广告),获取品牌流量商
     * 根据传入的高管信息，类型和交易数量判断资源类型*/
    @PostMapping("getResourcesByMember")
    public ResponseEntity getResourcesByMemberB(@RequestBody Resources resources, @RequestHeader(value = "userId")String userId){
        return memberResources.getResourcesByMember(resources,userId);
    }
    /**获取当前用户的会员订单*/
    @PostMapping("getListByUserId")
    public ResponseEntity getListByUserId(@RequestBody MemberOrder memberOrder, @RequestHeader(value = "userId")String userId){
        return memberInfoService.getListByUserId(memberOrder,userId);
    }

    /**删除会员订单*/
    @PostMapping("deleteOrder")
    public ResponseEntity deleteOrder(@RequestBody MemberOrder memberOrder, @RequestHeader(value = "userId")String userId){
        return memberInfoService.deleteOrder(memberOrder,userId);
    }

    /**支付*/
    @PostMapping("pay.do")
    public ResponseEntity pay(@RequestBody MemberType memberType, @RequestHeader(value = "userId") String userId){
        return memberInfoService.payForMember(memberType,userId);
    }

    /**
     * 接收支付宝回调请求
     * @param request
     * @return
     */
//    @PostMapping("alipay_callback.do")
//    public ResponseEntity alipayCallback(@RequestBody Requset request){
//        return memberInfoService.lipayCallback(request);
    @RequestMapping("alipay_callback.do")
    public String alipayCallback(HttpServletRequest request){
        return memberInfoService.lipayCallback(request);

    }

    /**
     * 主动查询支付宝订单的支付状态
     * @param
     * @return
     */
    @PostMapping("query_order_pay_status.do")
    public ResponseEntity query_order_pay_status(MemberOrder memberOrder){
        return memberInfoService.query_order_pay_status(memberOrder);
    }
}
